package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import menuActions.MenuAction;
import exceptions.NullCategoryException;

public class MenuBar extends JMenuBar
{

	public MenuBar() 
	{
		
	}
	
	public void addMenuItem(JMenu category, Map<JMenuItem, MenuAction> itemsAndActions) throws NullCategoryException
	{
		if(category != null)
		{
			for(final Entry<JMenuItem, MenuAction> entry : itemsAndActions.entrySet())
			{
				entry.getKey().addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent arg0) 
					{
						entry.getValue().executeAction();
					}
				});
				
				category.add(entry.getKey());
			}
			
			this.add(category);
		}
		else
		{
			throw new NullCategoryException();
		}
	}	
}
